glrenderer: Emit more useful error messages
authorBenjamin Otte <otte@redhat.com>
Thu, 3 Dec 2020 04:33:30 +0000 (05:33 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 3 Dec 2020 12:07:17 +0000 (13:07 +0100)
Catch the error when it happens, so that we can emit a specific and more
helpful error message.

Also verify that all branches in the code now do indeed set a proper
GError when they fail, so that the final catch-all is no longer needed.
Instead, assert that the error is set so that we catch future code
additions early that do not set the GError.

gsk/gl/gskglrenderer.c

index bb09be8bdd2203eb199a943d482bfd31c43bfb17..57b0767772387911c1670f723aadbe1891df8d72 100644 (file)
@@ -54,6 +54,8 @@
                               glGetUniformLocation(programs->program_name ## _program.id, "u_" #uniform_basename);\
                 if (programs->program_name ## _program.program_name.uniform_basename ## _location == -1) \
                   { \
+                    g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_LINK_FAILED, \
+                                 "Failed to find variable \"u_%s\" in shader program \"%s\"", #uniform_basename, #program_name); \
                     g_clear_pointer (&programs, gsk_gl_renderer_programs_unref); \
                     goto out; \
                   } \
@@ -3361,9 +3363,8 @@ gsk_gl_renderer_create_programs (GskGLRenderer  *self,
 out:
   gsk_gl_shader_builder_finish (&shader_builder);
 
-  if (error && !(*error) && !programs)
-    g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_COMPILATION_FAILED,
-                 "Failed to compile all shader programs"); /* Probably, eh. */
+  /* Check we indeed emitted an error if there was one */
+  g_assert (programs || !error || *error);
 
   return programs;
 }